<?php
$nocache = 'Pragma: no-cache';//不要缓存
header($nocache);
$nocache = 'Cache-Control: no-cache';//不要缓存
header($nocache);
require_once('./wss.php');
require_once('./class/db_o.php');
/*
	数据库共138个
	<aeiou>结尾为开音节
*/
//--------------------start
$mysql = new db_o; //类实例
//print_r($_POST);
$word=trim($_POST['word']); //查询输入
if(empty($word)){
	echo '输入为空';
	exit;
}
//------MAX
$sql_sentence = <<<EOBODY
	SELECT  *
	FROM `eng_strai`.`words`
EOBODY;
$sql_result = $mysql->s($sql_sentence);
$sql_r_n = mysql_num_rows($sql_result);//是否存在
//-----得到数据库内最长的值
$word_leng = 0;
$word_str = '';
for($i=0;$sql_r_n>$i;$i++){
	$r = mysql_fetch_array($sql_result,MYSQL_ASSOC);
	if(strlen($r['word'])>$word_leng){
		$word_leng = strlen($r['word']);
		$word_str = $r['word'];
	}
}
/*******
	echo $word_leng . "<br />\n";//最大长度
	echo $sql_r_n;//库内总行数
********/

//<--------切割查询 ---------beta
for($i=0;$word_leng>$i;$i++){
	print_r(reg_word_rarr($word,$i));   //截取 长单词的 部分
/****
	$reg '';
	$reg = '/^'.$reg.'[a-zA-Z]*'.'/i';
	if(preg_match($reg,$r['word'],$regarr_temp) ){
		
	}
*****/
}
//---fun
function reg_word_rarr($str_word,$word_subn){ //1=字串2=位数
	global $mysql;
	$sql_word = substr($str_word, 0, $word_subn+1);
	$sql_sentence = <<<EOBODY
	SELECT  *
	FROM `eng_strai`.`words`
	where `word` = '$sql_word'
EOBODY;
	
	$sql_result = $mysql->s($sql_sentence);
	$r_temp = Array();
	$r_temp[] = mysql_num_rows($sql_result);//是否存在
	for($i=0;$r_temp[0]>$i;$i++){
		$r = mysql_fetch_array($sql_result,MYSQL_ASSOC);
		$r_temp[] = $r['yb'];
	}
	return $r_temp;
}
//--------->
//--------显示内容
if ($word === '*'){
	$word = '%';
}
$sql_sentence = <<<EOBODY
	SELECT  *
	FROM `eng_strai`.`words`
	where `word` like '$word'
EOBODY;
$sql_result = $mysql->s($sql_sentence);
$sql_r_n = mysql_num_rows($sql_result);//是否存在
//--------显示 部分
if(!($sql_r_n == 0)){
?>
<table width="200" border="1">
	   <tr>
        <td width="40" >编号</td>
    	<td  >字母</td>
        <td  >读音</td>
      </tr>
<?
	for($i=0;$sql_r_n>$i;$i++){
		$r = mysql_fetch_array($sql_result,MYSQL_ASSOC);
		$td_info = $r['yb'];
		$td_word = $r['word'];
		
		echo <<<EOBODY
	      <tr>
	        <td >$i</td>
	        <td >$td_word</td>
	        <td  class="kk" >$td_info</td>
	      </tr>
EOBODY;
	}
?>
</table>
<?php
}else{ 
	echo '没有找到';
}
?>
